<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php echo (C("cfg_webname")); ?></title>
    <link href="/Application/Admin/Public/css/base.css" rel="stylesheet">
    <link rel="stylesheet" href="/Application/Admin/Public/custom/uimaker/easyui.css">
    <link rel="stylesheet" type="text/css" href="/Application/Admin/Public/custom/uimaker/icon.css">
    <style>
        #formAdd table{ width:100%;}
        #formAdd table td{ padding:5px;}
        #formAdd table td.td-left{text-align: right; padding-right: 10px;}
    </style>
</head>
<body>
<div class="container">
    <table id="tt"></table>

    <div id="DivAdd" class="easyui-dialog" style="width:450px;height:250px;padding:10px 20px" closed="true" resizable="true" modal="true" data-options="iconCls: 'icon-add',buttons: '#dlg-buttons'">
        <form id="formAdd" method="post" novalidate="novalidate">
            <input type="hidden" id="action" name="action">
            <input type="hidden" id="id" name="id">
            <table>
                <tr>
                    <td class="td-left" width="25%">城市名称:</td>
                    <td width="75%"><input class="easyui-textbox" type="text" name="area" disabled data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">城市编号:</td>
                    <td><input class="easyui-textbox" type="text" name="areacode" disabled data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">是否商用:
                    <td>
                        <input type="radio" name="is_business" value="1">是</input>
                        <input type="radio" name="is_business" value="2">否</input>
                    </td>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div id="dlg-buttons">
        <div style="text-align:right;">
            <a href="javascript:void(0)" class="easyui-linkbutton" id="btnAddOK" iconcls="icon-ok" onclick="btnAddOK()">确定</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#DivAdd').dialog('close')">关闭</a>
        </div>
    </div>
</div>


<script type="text/javascript" src="/Application/Admin/Public/custom/jquery.min.js"></script>
<script type="text/javascript" src="/Application/Admin/Public/custom/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/Application/Admin/Public/custom/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
        $('#tt').treegrid({
            url: '<?php echo U("area/arealist");?>',
            singleSelect: true,
            height: $(window).height(),
            title:'<div id="tb" style="padding:0 10px;">\n' +
            '<div>\n' +
            '<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit"  data-options="selected:true"  onclick = "editCasCasdeData()">修改</a>\n' +
            '</div>\n',

           idField: 'areacode',
            treeField: 'area',
            fitColumns: true,
            prerendered: false,
            frozenColumns: [[
                {field: 'chek', checkbox: true}
            ]],
            collapsible: false,
            loadMsg: '数据加载中...',
            animate: true,
            columns: [[
                {title: '城市名称', field: 'area', width: 180,},
                {title: '城市编号', field: 'areacode', width: 180,},
                {
                    title: '是否商用', field: 'is_business', width: 180,
                    formatter: function (val, row, index) {
                        if (val == 1) {
                            return "商用";
                        } else {
                            return "<span style='color: red'>" + "非商用" + "</span>";
                        }
                    }
                },
                {title: '排序', field: 'orderid', width: 180,},
            ]],
        });
    //修改
    function editCasCasdeData(id){
        var arr=$('#tt').datagrid('getSelections');
        if(!arr[0]){
            $.messager.alert('提示','请选择一条数据!');
            return false;
        }
        $("#DivAdd").dialog('open').dialog('setTitle', '修改级联');
        $('#formAdd').form('load',arr[0]);
        $('#action').val("update");
    }

    function btnAddOK() {
        var jsonCasData = $("#formAdd").serialize(); //序列化formAdd表单。
        $.ajax({
            url: '<?php echo U("area/change_business");?>', //将表单数据通过异步提交
            type: 'post',
            data: {
                jsonCasData: jsonCasData,
            },
            success: function (data) {
                if (data.status == 1) {
                    $.messager.alert('提示','修改成功!','info',function(){
                        window.location.reload();
                    });
                } else {
                    $.messager.alert('提示','修改失败!','info',function(){
                        window.location.reload();
                    });
                }

            },
            error: function () {
                $.messager.alert('提示',"数据错误！");
            }
        })
    }

</script>
</body>
</html>